package com.xiaoda.service.impl;

import com.xiaoda.dao.ArticleDao;
import com.xiaoda.dao.CollectDao;
import com.xiaoda.dao.CommentDao;
import com.xiaoda.dao.LikeDao;
import com.xiaoda.entity.Article;
import com.xiaoda.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleDao articleDao;

    @Autowired
    CollectDao collectDao;

    @Autowired
    CommentDao commentDao;

    @Autowired
    LikeDao likeDao;

    @Override
    public List<Article> findAll() {
        return articleDao.findAll();
    }

    @Override
    public Article findById(int id) {
        return articleDao.findById(id);
    }

    @Override
    public Article findFullById(int id) {
        return articleDao.findFullById(id);
    }

    @Override
    public List<Article> findByKeyword(String keyword, int start, int end) {
        return articleDao.findByKeyword(keyword, start, end);
    }

    @Override
    public List<Article> findConcern(String uid, int start, int end) {
        return articleDao.findConcern(uid, start, end);
    }

    @Override
    public List<Article> findMoreThan(int start, int end) {
        return articleDao.findMoreThan(start, end);
    }

    @Override
    public List<Article> findLessThan(int start, int end) {
        return articleDao.findLessThan(start, end);
    }

    @Override
    public List<Article> findTop50() {
        return articleDao.findTop50();
    }

    @Override
    public List<Article> findAllByUid(String uid, int start, int end) {
        return articleDao.findAllByUid(uid, start, end);
    }

    @Override
    public List<Article> findAllTreasured(String account, int start, int end) {
        return articleDao.findAllTreasured(account, start, end);
    }

    @Override
    public List<Article> findAllHobbies(String account, int start, int end) {
        return articleDao.findAllHobbies(account, start, end);
    }

    @Override
    public int countArticleNum(String account) {
        return articleDao.countArticleNum(account);
    }

    @Override
    public List<Article> findOtherArticles(String account, int aid) {
        return articleDao.findOtherArticles(account, aid);
    }

    @Override
    public int hasLook(int id) {
        return articleDao.hasLook(id);
    }

    @Override
    public int addArticle(String title, String content, String account) {
        return articleDao.addArticle(title, content, account);
    }

    @Override
    public int deleteByUid(String uid) {
        return articleDao.deleteByUid(uid);
    }

    @Override
    public List<Article> searchArticles(Map<String, Object> map) {
        return articleDao.searchArticles(map);
    }

    @Transactional
    @Override
    public int deleteById(int id) {
        collectDao.deleteByAid(id);
        commentDao.deleteByAid(id);
        likeDao.deleteByAid(id);
        return articleDao.deleteById(id);
    }

    @Override
    public int updateArticle(Map<String, Object> article) {
        return articleDao.updateArticle(article);
    }

    @Override
    public int insertArticle(Map<String, Object> map) {
        return articleDao.insertArticle(map);
    }

}
